const { ipcMain } = require("electron");
const { generalQuery, generalQueryPage, generalUpdate } = require('../modules/dataBase')
module.exports = () => {
    //患者信息的分页查询
    ipcMain.on('API-PATIENT-QUERY-PAGE', async (event, arg) => {
        const res = await generalQueryPage('patient', arg)
        const [total, rows] = res
        event.returnValue = { total, rows }
    })

    //患者信息的唯一查询
    ipcMain.on('API-PATIENT-QUERY-UNIQUE', async (event, id) => {
        event.returnValue = await generalQuery('patient', { id }, true)
    })

    //患者信息历史信息
    ipcMain.on('API-PATIENT-QUERY-HISTORY', async (event, name) => {
        event.returnValue = await generalQuery('patient', { name })
    })

    //患者查询
    ipcMain.on('API-PATIENT-QUERY', async (event, condition) => {
        event.returnValue = await generalQuery('patient', condition)
    })

    //编辑患者信息 条件是ID
    ipcMain.on('API-PATIENT-EDIT', async (event, arg) => {
        const condition = { id: arg.id }
        const data = { ...arg }
        data.id = undefined
        event.returnValue = await generalUpdate('patient', { condition, data })
    })
}